<?php
require_once dirname(__FILE__) . '/common.inc.php';

if (isset($_COOKIE[USER])) {
  $_SESSION[USER] = json_decode($_COOKIE[USER]);
}

$template = MiscUtils::getParam('t', 'test');
$options = MiscUtils::getParam('opts', json_encode(array()));
$base = MiscUtils::getParam('b', 'baseblank');

$smarty->assign('p', 'ui/default');
$smarty->assign('t', "$template");
$smarty->assign('u', json_encode((isset($_SESSION[USER])) ? $_SESSION[USER] : array()));
$smarty->assign('d', time());
$smarty->assign('opts', urldecode($options));
$message = array();
$message['images'] = DbUtils::get(DbUtils::createPdoInst(), TABLE_NAME_PREFIX_CUSTOM . "ivq_image", NULL, NULL, NULL, NULL, NULL, NULL)->d;

loadPage($template, $message);
$smarty->display("ui/default/$base.tpl");

function loadPage($template, $message) {
  switch ($template) {
    case 'test':
      test($message);
      break;
    default:
      header('Location: http://' . DOMAIN . PATH);
      break;
  }
}

function test($message) {
  global $smarty;
  require_once dirname(__FILE__) . '../_test/Image.class.php';
  $image = new Image();
  
  $idx = MiscUtils::getParam('i', 0);
  $message['idx'] = $idx;
  
  foreach ($message['images'] as &$msg) {
    $image->data($msg);
  }
  $smarty->assign('msg', json_encode($message));
}

?>